<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('项目名称') }}</td>
        <td>{{ form.dealName }}</td>
        <td class="tit">{{ $t('公司名称') }}</td>
        <td>{{ form.companyName }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目负责人') }}</td>
        <td>{{ form.personChargeName }}</td>
        <td class="tit">{{ $t('投资主体') }}</td>
        <td>{{ form.investName }}</td>
      </tr>
      <tr v-if="!form.icMeetingId">
        <td class="tit">{{ $t('预计投资金额') + $t('金额单位') }}</td>
        <td>{{ moneyFormat(form.expectedInvestAmount,'w') }}</td>
        <td class="tit">{{ $t('投资币种') }}</td>
        <td>{{ getCurrency }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请内容') }}</td>
        <td colspan="3">
          <div v-html="form.applyContent" />
        </td>
      </tr>
    </table>

    <div v-if="form.financeList && form.financeList.length > 0">
      <div class="area-header" style="margin-top: 15px;">
        <span class="area-header-title">{{ $t('财务尽调') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('机构名称') }}</th>
          <th>{{ $t('机构团队') }}</th>
          <th>{{ $t('中介报价(万)') }}</th>
          <th>{{ $t('是否中标') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.financeList" :key="ind">
            <td>{{ $t(getMediationName('KJS', v.agencyId)) }}</td>
            <td>{{ $t(getMediationTeamName(v.agencyId, v.agencyTeam)) }}</td>
            <td>{{ moneyFormat(v.agencyAmount,'w') }}</td>
            <td>{{ selectDictLabel(sysYesOptions,v.bidFlag) }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div v-if="form.legalList && form.legalList.length > 0">
      <div class="area-header" style="margin-top: 15px;">
        <span class="area-header-title">{{ $t('法务尽调') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('机构名称') }}</th>
          <th>{{ $t('机构团队') }}</th>
          <th>{{ $t('中介报价(万)') }}</th>
          <th>{{ $t('是否中标') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.legalList" :key="ind">
            <td>{{ $t(getMediationName('LS', v.agencyId)) }}</td>
            <td>{{ $t(getMediationTeamName(v.agencyId, v.agencyTeam)) }}</td>
            <td>{{ moneyFormat(v.agencyAmount,'w') }}</td>
            <td>{{ selectDictLabel(sysYesOptions,v.bidFlag) }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div v-if="form.industryList && form.industryList.length > 0">
      <div class="area-header" style="margin-top: 15px;">
        <span class="area-header-title">{{ $t('行业尽调') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('机构名称') }}</th>
          <th>{{ $t('机构团队') }}</th>
          <th>{{ $t('中介报价(万)') }}</th>
          <th>{{ $t('是否中标') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.industryList" :key="ind">
            <td>{{ $t(getMediationName('YWZX', v.agencyId)) }}</td>
            <td>{{ $t(getMediationTeamName(v.agencyId, v.agencyTeam)) }}</td>
            <td>{{ moneyFormat(v.agencyAmount,'w') }}</td>
            <td>{{ selectDictLabel(sysYesOptions,v.bidFlag) }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div v-if="form.backdropList && form.backdropList.length > 0">
      <div class="area-header" style="margin-top: 15px;">
        <span class="area-header-title">{{ $t('背景尽调') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('机构名称') }}</th>
          <th>{{ $t('机构团队') }}</th>
          <th>{{ $t('中介报价(万)') }}</th>
          <th>{{ $t('是否中标') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.backdropList" :key="ind">
            <td>{{ $t(getMediationName('BJDC', v.agencyId)) }}</td>
            <td>{{ $t(getMediationTeamName(v.agencyId, v.agencyTeam)) }}</td>
            <td>{{ moneyFormat(v.agencyAmount,'w') }}</td>
            <td>{{ selectDictLabel(sysYesOptions,v.bidFlag) }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div v-if="form.otherList && form.otherList.length > 0">
      <div class="area-header" style="margin-top: 15px;">
        <span class="area-header-title">{{ $t('其他尽调') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('机构名称') }}</th>
          <th>{{ $t('机构团队') }}</th>
          <th>{{ $t('中介报价(万)') }}</th>
          <th>{{ $t('是否中标') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.otherList" :key="ind">
            <td>{{ $t(getMediationName('other', v.agencyId)) }}</td>
            <td>{{ $t(getMediationTeamName(v.agencyId, v.agencyTeam)) }}</td>
            <td>{{ moneyFormat(v.agencyAmount,'w') }}</td>
            <td>{{ selectDictLabel(sysYesOptions,v.bidFlag) }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <FileView :list.sync="form.fileList" data-type="mt_meeting" :business-id="form.dealId" :btn-show="!otherBtnHide" />

  </div>
</template>

<script>
import { getMtMeeting } from '@/api/meeting/mtMeeting'
import { getFundName } from '@/api/fund/fundBase'
import { getUser } from '@/api/system/user'
import { moneyFormat, selectDictLabel } from '../../../utils/ruoyi'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      form: {},
      currencyOptions: {},
      otherBtnHide: false,
      sysYesOptions: []
    }
  },
  computed: {
    ...mapGetters(['getMediationList', 'getMediationTeamList']),
    getCurrency() {
      return this.selectDictLabel(this.currencyOptions, this.form.investCurrency)
    }
  },
  created() {
    this.$bus.$emit('async_done')
    this.getDicts('currency').then(res => {
      this.currencyOptions = res.data
    })
    this.getDicts('sys_yes_no').then(res => {
      this.sysYesOptions = res.data
    })
  },
  methods: {
    selectDictLabel,
    moneyFormat,
    getMediationName(type, id) {
      var mediationList = this.getMediationList(type)
      var mediation = mediationList.find(item => item.id === id)
      if (mediation) {
        return mediation.mediationShortName
      }
      return ''
    },
    getMediationTeamName(agencyId, id) {
      var mediationTeamList = this.getMediationTeamList(agencyId)
      var mediaTeam = mediationTeamList.find(item => item.id === id)
      if (mediaTeam) {
        return mediaTeam.deptId
      }
      return ''
    },
    init(data) {
      console.log(data, '打印页面')
      getMtMeeting(data.id).then(response => {
        this.form = response.data
        this.getFundName(this.form.investId)
        this.getPersonChargeName(this.form.personCharge)
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    getFundName(id) {
      getFundName(id).then(res => {
        // this.form.investName = res
        this.$set(this.form, 'investName', res)
      })
    },
    getPersonChargeName(userId) {
      getUser(userId).then(res => {
        // this.form.personChargeName = res.data.nickName
        this.$set(this.form, 'personChargeName', res.data.nickName)
        console.log(this.form)
      })
    },
    loadForm() {
      this.$nextTick(() => {
        this.formList = [
          { title: '申请单', value: 'input', type: 'table',
            tablePageList: [
              { title: '项目名称', type: 'title' },
              { title: '项目名称', value: 'dealName', type: 'input' },
              { title: '标的公司', type: 'title' },
              { title: '标的公司', value: 'companyName', type: 'input' },
              { title: '项目负责人', type: 'title' },
              { title: '项目负责人', value: 'personCharge', type: 'user', userMultiple: false },
              { title: '投资主体', type: 'title', vIf: this.isInit },
              { title: '投资主体', value: 'investId', type: 'fundselect', isShort: true, vIf: this.isInit },
              { title: '投资主体', type: 'title', vIf: !this.isInit },
              { title: '投资主体', value: 'investId', type: 'select', selectType: 'options', selectDataList: this.fundList, selectLabelParams: 'shortName', selectValueParams: 'investorId', vIf: !this.isInit },
              { title: '预计投资金额(万)', type: 'title', moneyUnit: 'w', vIf: !this.form.icMeetingId },
              { title: '预计投资金额(万)', value: 'expectedInvestAmount', type: 'money', moneyUnit: 'w', vIf: !this.form.icMeetingId },
              { title: '投资币种', type: 'title', vIf: !this.form.icMeetingId },
              { title: '投资币种', value: 'investCurrency', type: 'select', selectType: 'dict', dictVal: 'currency', vIf: !this.form.icMeetingId },
              { title: '申请标题', type: 'title' },
              { title: '申请标题', value: 'actTitle', type: 'textarea', width: '75%' },
              { title: '申请内容', type: 'title' },
              { title: '申请内容', value: 'applyContent', type: 'textarea', width: '75%' }
            ]
          },
          { title: '财务尽调', value: 'financeList', type: 'dataList', listType: 'vertical',
            vIf: this.form.financeList.length > 0 && this.form.meetingType === 'FK',
            listPageList: [
              { title: '机构名称', value: 'agencyId', type: 'select', selectOptions: this.getMediationList('KJS'), selectLabelParams: 'mediationShortName', selectValueParams: 'id' },
              { title: '机构团队', value: 'agencyTeam' },
              { title: '中介报价(万)', value: 'agencyAmount', type: 'money', moneyUnit: 'w' },
              { title: '是否中标', value: 'bidFlag', type: 'select', selectType: 'dict', dictVal: 'sys_yes_no' },
              { title: '备注', value: 'remark' }
            ]
          },
          { title: '法务尽调', value: 'legalList', type: 'dataList', listType: 'vertical',
            vIf: this.form.legalList.length > 0 && this.form.meetingType === 'FK',
            listPageList: [
              { title: '机构名称', value: 'agencyId', type: 'select', selectOptions: this.getMediationList('LS'), selectLabelParams: 'mediationShortName', selectValueParams: 'id' },
              { title: '机构团队', value: 'agencyTeam' },
              { title: '中介报价(万)', value: 'agencyAmount', type: 'money', moneyUnit: 'w' },
              { title: '是否中标', value: 'bidFlag', type: 'select', selectType: 'dict', dictVal: 'sys_yes_no' },
              { title: '备注', value: 'remark' }
            ]
          },
          { title: '行业尽调', value: 'industryList', type: 'dataList', listType: 'vertical',
            vIf: this.form.industryList.length > 0 && this.form.meetingType === 'FK',
            listPageList: [
              { title: '机构名称', value: 'agencyId', type: 'select', selectOptions: this.getMediationList('YWZX'), selectLabelParams: 'mediationShortName', selectValueParams: 'id' },
              { title: '机构团队', value: 'agencyTeam' },
              { title: '中介报价(万)', value: 'agencyAmount', type: 'money', moneyUnit: 'w' },
              { title: '是否中标', value: 'bidFlag', type: 'select', selectType: 'dict', dictVal: 'sys_yes_no' },
              { title: '备注', value: 'remark' }
            ]
          },
          { title: '背景尽调', value: 'backdropList', type: 'dataList', listType: 'vertical',
            vIf: this.form.backdropList.length > 0 && this.form.meetingType === 'FK',
            listPageList: [
              { title: '机构名称', value: 'agencyId', type: 'select', selectOptions: this.getMediationList('BJDC'), selectLabelParams: 'mediationShortName', selectValueParams: 'id' },
              { title: '机构团队', value: 'agencyTeam' },
              { title: '中介报价(万)', value: 'agencyAmount', type: 'money', moneyUnit: 'w' },
              { title: '是否中标', value: 'bidFlag', type: 'select', selectType: 'dict', dictVal: 'sys_yes_no' },
              { title: '备注', value: 'remark' }
            ]
          },
          { title: '其他尽调', value: 'otherList', type: 'dataList', listType: 'vertical',
            vIf: this.form.otherList.length > 0 && this.form.meetingType === 'FK',
            listPageList: [
              { title: '机构名称', value: 'agencyId', type: 'select', selectOptions: this.getMediationList('other'), selectLabelParams: 'mediationShortName', selectValueParams: 'id' },
              { title: '机构团队', value: 'agencyTeam' },
              { title: '中介报价(万)', value: 'agencyAmount', type: 'money', moneyUnit: 'w' },
              { title: '是否中标', value: 'bidFlag', type: 'select', selectType: 'dict', dictVal: 'sys_yes_no' },
              { title: '备注', value: 'remark' }
            ]
          },
          { title: '附件信息', value: 'fileList', type: 'fileList', listType: 'vertical',
            vIf: this.form.fileList.length > 0,
            listPageList: [
              { title: '文件分类', value: 'directoryName' },
              { title: '附件名称', value: 'name' },
              { title: '备注', value: 'remark' },
              { title: '上传人', value: 'updateBy', childrenValue: 'nickName' },
              { title: '上传时间', value: 'createTime' }
            ]
          }
        ]
      })
    }
  }
}
</script>
